package com.niiwoo.civet.account.service.local.check.job.check;

import java.util.HashMap;
import java.util.Map;

import com.niiwoo.civet.account.service.local.check.job.api.ParseService;
import com.niiwoo.civet.account.service.local.check.job.properties.AccountCheckingProperties;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TypeDispatcher {
	@SuppressWarnings("rawtypes")
	private Map<String, NumDispatcher> map = new HashMap<String, NumDispatcher>();
	
	private AccountCheckingProperties properties;
	
	public TypeDispatcher(AccountCheckingProperties properties) {
		this.properties = properties;
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public void registeDispatcher(String parseServiceName, ParseService parseService) {
		if (!map.containsKey(parseServiceName)) {
			map.put(parseServiceName, new NumDispatcher(properties, parseService));
		}
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public void dispath(String parseServiceName, Object obj) {
		NumDispatcher dispatcher = map.get(parseServiceName);
		if (dispatcher == null) {
			//抛出异常
			log.error("dispatcher is null. [{}]", parseServiceName);
		}
		
		dispatcher.receive(obj);
	}

	@SuppressWarnings({ "rawtypes"})
	public void notifyDone(String parseServiceName) {
		NumDispatcher dispatcher = map.get(parseServiceName);
		dispatcher.notifyDone();
	}
}
